<?php

use yii\helpers\Html;
use kartik\form\ActiveForm;
use common\assets\WangEditorV4;

/* @var $this yii\web\View */
/* @var $model \admin\modules\product\models\forms\FormMaterial */

WangEditorV4::register($this)
?>
<div class="products-update">

    <?php $form = ActiveForm::begin(); ?>
    <?= $form->field($model, 'product_id')->hiddenInput()->label(false) ?>

    <?=$form->field($model, 'content')->textarea(['class' => "product-material hidden"]) ?>
    <div class="openEditor"></div>

    <?php if (!Yii::$app->request->isAjax){ ?>
        <div class="form-group">
            <?= Html::submitButton('保存', ['class' => 'btn btn-primary']) ?>
        </div>
    <?php } ?>
    <?php ActiveForm::end(); ?>

</div>

<?php
$uploadImgServer = Yii::$app->urlManager->createUrl('/pub/ajax/wang-upload-images');
$uploadVideoServer = Yii::$app->urlManager->createUrl('/pub/ajax/wang-upload-video');
$js = <<<JS
var initContent = '{$model->content}'
if (typeof editor !== "undefined") {
    delete editor;
}
var editor = new window.wangEditor('.openEditor')
editor.config.height = 800
// editor.config.withCredentials = true
editor.config.uploadImgServer = "{$uploadImgServer}";
editor.config.uploadImgMaxSize = 2 * 1024 * 1024 // 2M
editor.config.uploadImgMaxLength = 10 // 一次最多上传 10 个图片
//editor.config.uploadVideoServer = '{$uploadVideoServer}';
//editor.config.uploadVideoAccept = ['mp4', 'MP4', 'mov', 'MOV'];
//editor.config.uploadVideoMaxSize = 20 * 1024 * 1024 // 20M
editor.config.onchange = function (html) {
    $('.product-material').val(html)
}
editor.create()
editor.txt.html(initContent)
JS;

$this->registerJs($js);
?>
